package com.zxh.system.controller;

import com.zxh.system.domain.JsonResult;
import com.zxh.system.exception.MethodNotDefinedException;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

public abstract class BaseController<T> {

    @InitBinder
    public void initBinder(WebDataBinder binder){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setLenient(true);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf,true));
    }


    public JsonResult<T> save(T t){
        throw new MethodNotDefinedException(getClass(),"save");
    }

    public JsonResult<T> update(T t){
        throw new MethodNotDefinedException(getClass(),"update");
    }

    public JsonResult<T> get(Serializable id){
        throw new MethodNotDefinedException(getClass(),"update");
    }

    public JsonResult<T> query(PageRequest page,T t){
        throw new MethodNotDefinedException(getClass(),"query");
    }
}
